package com.quick.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.quick.annotation.IgnoreToken;
import com.quick.annotation.RedisLock;
import com.quick.login.doamin.dto.UserLoginDTO;
import com.quick.login.doamin.vo.QuickUserVo;
import com.quick.service.IUserLoginService;

@RestController
@Api(tags = "用户登录")
@RequestMapping("api/user")
@Slf4j
public class UserLoginController {
	
	@Autowired
	private IUserLoginService userLoginService;
	
	@PostMapping("login")
	@ApiOperation("用户登录")
	@RedisLock("#login.userName")
	@IgnoreToken
	public  String login(@RequestBody UserLoginDTO login) {
		String res = userLoginService.login(login);
		log.info("res:{}", res);
		return res;
	}

	@GetMapping("getUser")
	@ApiOperation("获取当前用户")
	public QuickUserVo getUser() {
		return userLoginService.getUser();
	}

	public Boolean logout() {
		return true;
	}

	@PostMapping("register")
	@ApiOperation("用户注册")
	public Boolean register(@RequestBody UserLoginDTO register){
		return userLoginService.register(register);
	}
	
	@GetMapping("captchaImage")
	@ApiOperation("获取验证图片")
	public String captchaImage() {
		return "0001001";
	}

}
